package io.renren.controller;

import io.renren.common.utils.R;
import io.renren.service.business.ArticleBusinessService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Map;

/**
 * @author Chenjiacheng
 */
@RestController
@RequestMapping("/article")
@Api(tags="文章模块接口")
public class ArticleController {

    @Autowired
    private ArticleBusinessService articleBusinessService;

    // 获取轮播资讯接口

    // 获取资讯列表接口
    @GetMapping("/list")
    public R lList( Map<String,Object> param ){
        Integer page = (Integer) param.get("page");
        if( page == null ){
            page = 1;
        }
        return R.ok().put( "data", articleBusinessService.getArticleList( page )  );
    }

    // 获取资讯详情接口
    @GetMapping("/detail")
    public R detail( Map<String,Object> param ){
        Integer articleId = (Integer) param.get("articleId");
        return R.ok().put( "data", articleBusinessService.queryArticleDetail( articleId ) );
    }

    // 获取资讯评论列表接口
    @GetMapping("/evaluate/list")
    public R evaluateList( Map<String,Object> param ){
        Integer page = (Integer) param.get("page");
        return R.ok().put("data", articleBusinessService.getArticleCommentList( page == null ? 1 : page ));

    }

    // 评价资讯接口
    @GetMapping("/evaluate")
    public R evaluate( Map<String,Object> param ){
        Integer userId = (Integer) param.get("userId");
        Integer articleId = (Integer) param.get("articleId");
        String content = (String) param.get("content");
        articleBusinessService.evaluate( userId, articleId, content );
        return R.ok();
    }

    // 搜索资讯接口
    @GetMapping("/search")
    public R search( Map<String,Object> param ){
        String key = (String) param.get("key");
        return R.ok().put("data", new ArrayList() );
    }

}
